home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE09 / CODERS / EXPTTOOL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-03-20  |  5.6 KB  |  220 lines

  1. unit ExptTool ;
  2. (*****) interface (*******************************)
  3. uses
  4.   WinTypes,
  5.   winProcs,
  6.   Messages,
  7.   SysUtils,
  8.   Classes,
  9.   KeyDefs ;
  10.  
  11.  
  12. type
  13.   TTitleBuffer = array [0..127] of char ;
  14.  
  15.   TIconListRec = class
  16.     TheIcon : HIcon ;
  17.     TheWindow : HWnd ;
  18.   end ;
  19.  
  20. function FindChild( WindowName, ChildName : string ) : HWnd ;
  21. Function GetEditControl : HWnd;
  22.  
  23. procedure ListWindowTitles( Start : HWnd ; var WndList : TStringList ) ;
  24. procedure ListTopLevelWindows( Start : HWnd ; var WndList : TStringList ) ;
  25. function FindPartialWindowTitle( Title : string ) : HWnd ;
  26. function StayOnTop( Wnd : HWnd ) : boolean ;
  27. function NoStayOnTop( Wnd : HWnd ) : boolean ;
  28.  
  29. function SendKeys( S : string ) : TSendKeyError ;
  30. procedure TileChildWindows( Wnd : HWnd ; Flags : bool ) ;
  31. procedure CascadeChildWindows( Wnd : HWnd ; Flags : bool ) ;
  32. procedure SwitchToThisWindow( Wnd : HWnd ; Flags : bool ) ;
  33. function IsWinOldApTask( Task : THandle ) : boolean ;
  34.  
  35. (*****) implementation (**************************)
  36.  
  37. procedure ListWindowTitles( Start : HWnd ; var WndList : TStringList ) ;
  38. var
  39.   Wnd : HWnd ;
  40.   Buff : TTitleBuffer ;
  41. begin
  42.   Wnd := GetWindow( Start, GW_CHILD ) ;
  43.   while Wnd > 0 do
  44.   begin
  45.     if
  46.     (* window is visible *)
  47.       ( IsWindowVisible( Wnd ))
  48.     and
  49.     (* window has non-null title *)
  50.       ( GetWindowText( Wnd, buff, SizeOf( buff )) > 0 )
  51.     then
  52.       WndList.Add( StrPas( buff )) ;
  53.     Wnd := GetWindow( Wnd, GW_HWNDNEXT ) ;
  54.   end ;
  55. end ;
  56.  
  57. procedure ListTopLevelWindows( Start : HWnd ; var WndList : TStringList ) ;
  58. var
  59.   Wnd : HWnd ;
  60.   Buff : TTitleBuffer ;
  61. begin
  62.   Wnd := GetWindow( Start, GW_HWNDFIRST ) ;
  63.   while Wnd <> 0 do
  64.   begin
  65.     if
  66.     (* window is visible *)
  67.       ( IsWindowVisible( Wnd ))
  68.     and
  69.     (* window is "top level" (owner is Desktop window ) *)
  70.       ( GetWindow( Wnd, GW_OWNER ) = 0 )
  71.     and
  72.     (* window has non-null title *)
  73.       ( GetWindowText( Wnd, buff, SizeOf( buff )) > 0 )
  74.     then
  75.       WndList.Add( StrPas( buff )) ;
  76.     Wnd := GetWindow( Wnd, GW_HWNDNEXT ) ;
  77.   end ;
  78. end ;
  79.  
  80. function StayOnTop( Wnd : HWnd ) : boolean ;
  81. begin
  82.   Result := FALSE ;
  83.   if IsWindow( Wnd ) then
  84.   begin
  85.    SetWindowPos( Wnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE ) ;
  86.    Result := TRUE ;
  87.   end ;
  88. end ;
  89.  
  90. function NoStayOnTop( Wnd : HWnd ) : boolean ;
  91. begin
  92.   Result := FALSE ;
  93.   if IsWindow( Wnd ) then
  94.   begin
  95.    SetWindowPos( Wnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE ) ;
  96.    Result := TRUE ;
  97.   end ;
  98. end ;
  99.  
  100. {
  101. function FindPartialWindowTitle( Title : string ) : HWnd ;
  102. var
  103.   Wnd : HWnd ;
  104.   TitleBuff : TTitleBuffer ;
  105. begin
  106.   Result := 0 ;
  107.   Wnd := GetWindow( GetDesktopWindow, GW_CHILD ) ;
  108.   while ( Wnd <> 0 ) do
  109.   begin
  110.     GetWindowText( Wnd, TitleBuff, SizeOf( TitleBuff )) ;
  111.     if Pos( UpperCase( Title ), UpperCase( StrPas( TitleBuff ))) > 0 then
  112.     begin
  113.       Result := Wnd ;
  114.       Exit ;
  115.     end ;
  116.     Wnd := GetWindow( Wnd, GW_HWNDNEXT ) ;
  117.   end ;
  118. end ;
  119. }
  120.  
  121. function FindPartialWindowTitle( Title : string ) : HWnd ;
  122. var
  123.   Titles : TStringList ;
  124.   i : integer ;
  125.   Found : boolean ;
  126.   TitleBuff : TTitleBuffer ;
  127. begin
  128.   Result := 0 ;
  129.   Titles := TStringList.Create ;
  130.   Titles.Clear ;
  131.  
  132.   ListWindowTitles( GetDesktopWindow, Titles ) ;
  133.  
  134.   i := 0 ;
  135.   Found := FALSE ;
  136.   while ( i <= Titles.Count - 1 ) and ( not Found ) do
  137.   begin
  138.     if Pos( UpperCase( Title ), UpperCase( Titles[i] )) > 0 then
  139.     begin
  140.       Found := TRUE ;
  141.       Result := FindWindow( nil, StrPCopy( TitleBuff, Titles[i] )) ;
  142.     end
  143.     else
  144.       Inc( i ) ;
  145.   end ;
  146.  
  147.   Titles.Free ;
  148. end ;
  149.  
  150. Function GetEditControl : HWnd;
  151. Var
  152.    Wnd : HWND;
  153.    Name : Array[0..32] Of Char;
  154. Begin
  155.    Wnd := GetWindow(FindWindow('TEditWindow', Nil), GW_CHILD);
  156.    While Wnd <> 0 Do
  157.       Begin
  158.          GetClassName(Wnd, Name, 32);
  159.          If StrComp(Name, 'TEditControl') = 0 Then
  160.             Begin
  161.                GetEditControl := Wnd;
  162.                Exit;
  163.             End;
  164.          Wnd := GetWindow(Wnd, GW_HWNDNEXT);
  165.       End;
  166.    GetEditControl := 0;
  167.    MessageBox( 0, 'Window not found', 'Error', MB_OK ) ;
  168. End;
  169.  
  170. function FindChild( WindowName, ChildName : string ) : HWnd ;
  171. var
  172.   Wnd  : HWnd ;
  173.   TempBuff    : array[0..32] Of char ;
  174.   WindowBuff, ChildBuff : TTitleBuffer ;
  175. begin
  176.   Result := 0 ;
  177.   StrPCopy( WindowBuff, WindowName ) ;
  178.   StrPCopy( ChildBuff, ChildName ) ;
  179.  
  180.   (* find parent window handle from classname *)
  181.   (* then get first child window handle *)
  182.   Wnd := GetWindow( FindWindow( WindowBuff, nil ), GW_CHILD) ;
  183.  
  184.   while Wnd <> 0 do  (* GetWindow returns 0 when no more windows to iterate *)
  185.   begin
  186.     (* get classname of child winodow *)
  187.     GetClassName( Wnd, TempBuff, 32 ) ;
  188.  
  189.  
  190.     if StrComp( TempBuff, ChildBuff ) <> 0 then
  191.     (* if obtained class name <> desired one then get next child window *)
  192.       Wnd := GetWindow( Wnd, GW_HWNDNEXT )
  193.  
  194.     else
  195.     begin
  196.       (* return found child window handle *)
  197.       Result := Wnd ;
  198.       Exit ;
  199.     end;
  200.   end;
  201. end;
  202.  
  203. function SendKeys( S : string ) : TSendKeyError ; external 'SKEYS' ;
  204. procedure TileChildWindows( Wnd : HWnd ; Flags : bool ) ; external 'USER' ;
  205. procedure CascadeChildWindows( Wnd : HWnd ; Flags : bool ) ; external 'USER' ;
  206. procedure SwitchToThisWindow( Wnd : HWnd ; Flags : bool ) ; external 'USER' ;
  207. function IsWinOldApTask( Task : THandle ) : boolean ; external 'KERNEL' ;
  208.  
  209. {$ifdef VER80}
  210. initialization
  211. {$else}
  212. begin
  213. {$endif}
  214.     (* unit ExptTool -- initialization code *)
  215.   (* NONE *)
  216. end (* unit ExptTool -- initialization code *) .
  217.  
  218.  
  219.  
  220.